package tr3dtris.game.controller;

import tr3dtris.game.controller.inputMapper.AbstractInputMapper;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
import tr3dtris.game.GameActions;

/**
 * Class used as key listener. It capture user input on keyboard and delegate
 * the management to a connected <AbstractInputMapper> object.
 * @author Luciano Mammino <loige@hotmail.com>
 * @author Andrea Mangano <kapitan0@hotmail.it>
 * @version 0.1
 * @since 0.1
 */
public class ControllerListener implements KeyListener
{

    /**
     * Reference to the connected <AbstractInputMapper>
     */
    private GameActions gameActions;
    private AbstractInputMapper inputMapper;

    /**
     * Constructor. Creates a new <ControllerListener> for a given <GameActions>
     * and a given <AbstractInputMapper>
     * @param gameActions
     * @param inputMapper
     */
    public ControllerListener(GameActions gameActions, AbstractInputMapper inputMapper)
    {
        this.gameActions = gameActions;
        this.inputMapper = inputMapper;
    }

    /**
     * {@inheritDoc}
     */
    public void keyTyped(KeyEvent e) {
        this.getInputMapper().parseKeyTyped(e);
    }

    /**
     * {@inheritDoc}
     */
    public void keyPressed(KeyEvent e) {
        this.getInputMapper().parseKeyPressed(e);
    }

    /**
     * {@inheritDoc}
     */
    public void keyReleased(KeyEvent e) {
        this.getInputMapper().parseKeyReleased(e);
    }

    /**
     * @return the gameActions
     */
    public GameActions getGameActions() {
        return gameActions;
    }

    /**
     * @return the inputMapper
     */
    public AbstractInputMapper getInputMapper() {
        return inputMapper;
    }

}
